const express = require("express");
const multer = require("multer");
const router = express.Router();
const activityController = require("../../controllers/wechat/activity");

let storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, "./public/uploads");
  },

  filename: function (req, file, cb) {
    var fileFormat = file.originalname.split(".");
    cb(
      null,
      file.fieldname +
      "-" +
      Date.now() +
      "." +
      fileFormat[fileFormat.length - 1]
    );
  },
});

let upload = multer({
  storage: storage,
});

// 活动分类
router.get("/type", function (req, res) {
  res.render("index", { title: "Express" });
});

// 参与活动
router.get("/join", activityController.join);

// 获取活动
router.get("/list", activityController.list);

// 活动详情
router.get("/detail", activityController.detail);

// 删除活动
router.post("/del", function (req, res) {
  res.render("index", { title: "Express" });
});

// 发布活动
router.post("/add", activityController.add);

// 活动图片上传
router.post(
  "/uploadpreview",
  upload.single("img"),
  activityController.uploadpreview
);

// 活动通知
router.get('/activityjoinnotify', activityController.activityJoinNotify);

// 编辑活动
router.post("/edit", function (req, res) {
  res.render("index", { title: "Express" });
});

module.exports = router;
